Tootsville::Defrecord

Macro

Defrecord names a macro, with lambda list (NAME (DATABASE TABLE &KEY PULL ID-COLUMN) &REST COLUMNS):

Define a database-mapping object type NAME, for DATABASE and TABLE, with COLUMNS.

DATABASE is the symbolic name of the database, mapped via TOOTSVILLE CONFIG; eg, :friendly

TABLE is the string table-name, exactly as it exists in the database; eg, "toots"

PULL is meant to indicate an infrequently-changed, short table (ie, basically a small enumeration) that should be pulled into local cache up-front and referenced from there directly.

COLUMNS are a table of names, types, and foreign-key references, in the form: (LABEL TYPE &rest REFERENCE)

The LABEL of a column is mapped via TOOTSVILLE LISP-TO-DB-NAME; it is the Lisp name which is essentially the same as the SQL name, but with KEBAB-CASE rather than snake_case.

When present, REFERENCE is the symbol REF followed by the record-type (class) to whose primary key (ID or UUID) the reference is made. NUMBER REF columns point to ID, UUID REF columns to UUID.

TYPE is one of the following:

NUMBER
map to an integer or real column in the database
STRING
map to a CHAR, CHAR VARYING, or TEXT column, or ENUM
COLOR24
stored in the database as a 24-bit BINARY (3 bytes)
KEYWORD
map to a CHAR or CHAR VARYING column, or ENUM
UUID
stored as a 128-bit BINARY (16 bytes)
JSON
stored as a TEXT column, but parsed on loading via Jonathan
YORNP
a boolean, stored as (typically an enum) 'Y' or 'N'.
URI
stored as CHAR VARying or TEXT, parsed at load time as a PURI:URI.
TIMESTAMP
translates to a LOCAL-TIME:TIMESTAMP on loading.

File

Defined in file src/db/db-central.lisp.